import java.util.Arrays;

class Solution {
    public int longestConsecutive(int[] nums) {

        int n=nums.length;
        if(n<=1) return n;
        int max=1;
        Arrays.sort(nums);
        int[] dp=new int[n+1];
        dp[0]=1;
        for(int i=1;i<n;i++){
            dp[i]=1;

            if(nums[i]==nums[i-1]+1){
                dp[i]=dp[i-1]+1;
                max=Math.max(dp[i],max);

            }else if(nums[i]==nums[i-1]){
                dp[i]=dp[i-1];
            }


        }
        return max;
    }
}